# -*- coding: utf-8 -*-
import os
from datetime import timedelta


class Config():
    # 日志配置
    LOGGING_LEVEL = 'DEBUG'
    LOGGING_FILE_MAX_BYTES = 300 * 1024 * 1024
    LOGGING_FILE_BACKUP = 10

    # flask-sqlalchemy使用的参数
    # 默认数据库
    SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')  # 数据库
    SQLALCHEMY_POOL_SIZE = 10
    SQLALCHEMY_POOL_RECYCLE = 7200
    SQLALCHEMY_MAX_OVERFLOW = 15
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 追踪数据的修改信号
    SQLALCHEMY_ECHO = False

    CELERY_CONFIG = {
        'broker_url': 'redis://172.16.80.121:6379/13',
        'result_backend': 'redis://172.16.80.121:6379/14',
    }

    # celery 配置
    CELERY_DEFAULT_CONFIG = {
        'task_serializer': 'json',
        'result_serializer': 'json',
        'accept_content': ['json'],
        'timezone': 'Asia/Shanghai',
        'enable_utc': False,
        'worker_max_tasks_per_child': 60,
        'result_expires': 500,
        'task_time_limit': 60,
        'worker_concurrency': 10,
        'broker_connection_retry_on_startup': False,
        'celery_beat_schedule': {
            "add-every-5s": {
                "task": "celery_tasks.sample.tasks.async_add",
                'schedule': 5.0,  # 每30秒执行1次
                'args': (3, 8)  # 传递参数-
            },
            "add-every-day": {
                "task": "celery_tasks.sample.tasks.async_add_2",
                'schedule': timedelta(hours=1), # 每小时执行1次
                'args': (6, 6)  # 传递参数-
            },
        }
    }

try:
    from .local_setting import LocalDevelopmentConfig

    development_config = LocalDevelopmentConfig
except ModuleNotFoundError:
    development_config = Config

config_dict = {
    'development': development_config,
    # 'production': ProductionConfig,
    # 'testing': TestingConfig
}
